package org.hgvc.webapp.ets.jsf.beans.admin;

import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.event.ActionEvent;

import org.hgvc.webapp.ets.bo.Partner;
import org.hgvc.webapp.ets.constant.PartnerConstant;
import org.hgvc.webapp.ets.spring.service.PartnerService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;
import org.jocsb.base.util.FacesUtils;



public class AdminPartnerPendingApprovalManagementBean extends AbstractBean {

	public static final String BEAN_NAME="adminPartnerPendingApprovalManagementBean";
	private PartnerService service;
	private List<Partner> partnerList;
	private Partner partner;
	private String name;
	private String code;
	private String pendingStatus = PartnerConstant.PARTNER_STATUS_PENDING_APPROVAL_REG;
	private String checkListStatus = PartnerConstant.PARTNER_STATUS_PENDING_CHECK_LIST;
	public static final String NAV_LIST_PARTNER="adminPendingAppPartnerMgmt";
	private boolean searchInvoked;
	private String currentTabStatus;
	
	
	
	public String getCurrentTabStatus() {
		return currentTabStatus;
	}
	public void setService(PartnerService service) {
		this.service = service;
	}
	public void setPartnerList(List<Partner> partnerList) {
		this.partnerList = partnerList;
	}
	public Partner getPartner() {
		return partner;
	}
	public void setPartner(Partner partner) {
		this.partner = partner;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getPendingStatus() {
		return pendingStatus;
	}
	public String getCheckListStatus() {
		return checkListStatus;
	}
	/*----------------------------------------------------------------*/

	public List<Partner> getPartnerList() {
		try{
			if (!searchInvoked)
				partnerList = service.getPendingApprovalPartner();
			//partnerList = service.searchRegNoPartnerNameInList(regno, name, partnerList);
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return partnerList;
	}
	
	public String searchAction(){
		return NAV_LIST_PARTNER.concat("_"+getRoleName());
	}
	public void searchActionListener(ActionEvent event){
		try{
			searchInvoked=true;
			this.partnerList= service.searchPartnerList(code,name);
	//		System.out.println("partnerList.size()="+partnerList.size());
		}catch(BaseException be){
			initErrorBean(be);
		}
	}
	
	public String navListAction(){
		return NAV_LIST_PARTNER.concat("_"+getRoleName());
	}
	
	public void checkListActionListener(ActionEvent ae){
		UIParameter param = (UIParameter)ae.getComponent().findComponent("partnerId");
		String id = (String)param.getValue();
		for(Partner p:partnerList){
			if(p.getPartnerId().equalsIgnoreCase(id)){
				partner = p;
				break;
			}
		}
	}

	public String checkListAction(){
		AdminPartnerCheckListBean bean = (AdminPartnerCheckListBean)FacesUtils.getManagedBean(AdminPartnerCheckListBean.BEAN_NAME);
		return bean.navDocCheckListAction(partner);
	}
	
	public String backAction(){
		return AdminPortalBean.NAV_ADMIN_PORTAL.concat("_"+getRoleName());
	}
	
	public void navPartnerProfileActionListener(ActionEvent ae){
		UIParameter param = (UIParameter)ae.getComponent().findComponent("pId");
		String id = (String)param.getValue();
		for(Partner p:partnerList){
			if(p.getPartnerId().equalsIgnoreCase(id)){
				partner = p;
				break;
			}
		}
	}
	
	public String navPartnerProfileAction(){
		AdminPartnerProfileBean bean = (AdminPartnerProfileBean)FacesUtils.getManagedBean(AdminPartnerProfileBean.BEAN_NAME);
		return bean.navVewAction(partner);
	}
}
